<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="报告名称">
              <j-input placeholder="请输入报告名称" v-model="queryParam.reportName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>
              <!-- <a-button type="primary" style="margin-left: 8px" @click="handleRun">生成报告</a-button> -->
              <a-button @click="goCronJob" type="primary" icon="setting" style="margin-left: 8px">设置定时报告</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div> 
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading" 
        @change="handleTableChange"
      > 
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleRun(record)">生成报告</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
            <a-divider type="vertical" />
          <a @click="handleHistory(record)"  :disabled="record.tableName==''">历史数据</a>
        </span>
      </a-table>
    </div>

    <user-reports-modal ref="modalForm" @ok="modalFormOk" />
    <build-modal ref="buildModal" />  
    <report-cron-job-data-set-modal ref="reportCronJobDataSetModal"/> 
    <user-reports-history-modal ref="userReportsHistoryModal"/>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import UserReportsModal from './modules/UserReportsModal'
import BuildModal from './Build' 
import ReportCronJobDataSetModal from '@/views/corp/reportCronJob/ReportCronJobDataSetList'
import UserReportsHistoryModal from './UserReportsHistoryModal'

import '@/assets/less/TableExpand.less'

export default {
  name: 'UserReportsList',
  mixins: [JeecgListMixin],
  components: {
    UserReportsModal,
    BuildModal, 
    ReportCronJobDataSetModal,
    UserReportsHistoryModal
  },
  data() {
    return {
      description: '报告管理页面',
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key: 'rowIndex',
        //   width: 60,
        //   align: 'center',
        //   customRender: function (t, r, index) {
        //     return parseInt(index) + 1
        //   },
        // },
         {
          title: '报告ID',
          align: 'center',
          dataIndex: 'id',
          width: 160,
        },
        {
          title: '报告名称',
          align: 'left',
          dataIndex: 'reportName',
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
        },
        // {
        //   title: '创建人',
        //   align: 'center',
        //   dataIndex: 'userId',
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/userReports/userReports/list',
        delete: '/userReports/userReports/delete',
        deleteBatch: '/userReports/userReports/deleteBatch',
        exportXlsUrl: '/userReports/userReports/exportXls',
        importExcelUrl: 'userReports/userReports/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'reportName', text: '报告名称', dictCode: '' })
      fieldList.push({ type: 'date', value: 'createDate', text: '创建日期' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'userId', text: '创建人', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleRun: function (record) {
        var that = this
        that.$refs.buildModal.show(record);
        return;
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一项！')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        var that = this
        that.$refs.buildModal.show(this.selectionRows[0])
      }
    },
    handleHistory(record){ 
       this.$refs.userReportsHistoryModal.show(record);
    },
    goCronJob(){
       this.$refs.reportCronJobDataSetModal.show();
    },
    downloadFile(text){ 
      let url = window._CONFIG['domianURL'] + + '/sys/common/download/' + text;
      window.open(url);
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>